#ifndef NR_NET_SERVER_H
#define NR_NET_SERVER_H

#include "nr_std.h"
#include "nr_net_command.h"
#include "nr_net_socket.h"
#include "nr_net_server_logic.h"

class QTcpServer;

typedef QHash<nr_id_t, nr_net_socket*> nr_net_sockets;

class nr_net_server : public QObject
{
    Q_OBJECT
public:
    nr_net_server(QObject *parent, nr_object_manager& object_manager);

    virtual ~nr_net_server(void);

    quint16& port() { return m_port; }

    nr_error_t start();
    nr_error_t stop();
    
private:
    bool check_header(const nr_net_command_header& header);
    void close_session(nr_net_socket *socket);

    QTcpServer *m_tcp_server;
    quint16 m_port;
    
    nr_net_sockets m_net_sockets;
    QTimer m_check_timer;
    nr_net_server_logic m_logic;
    
    private slots:
        void accept_connection();
        void read_data(nr_net_socket *);
        void timer_check_state();
};


#endif // NR_NET_SERVER_H
